package com.four.bmm.controller;

import com.four.bmm.service.NewsService;
import com.four.bmm.util.JsonUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/MinusClickcountServlet")
public class MinusClickcountServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int newsId= Integer.parseInt(req.getParameter("newsid"));
        NewsService newsService=new NewsService();
        newsService.minusClickCount(newsId);
        int clickcount=newsService.getNewsById(newsId).getClickcount();
        JsonUtil.toJson(resp,clickcount);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
